﻿#coding=utf-8
from django.views.decorators.csrf import csrf_protect
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils import simplejson
from main.models import Film
from django.contrib.auth.models import User


@csrf_protect
def main(request):
    return render_to_response("main.html",context_instance=RequestContext(request))

@csrf_protect        
def new_film(request):
    if request.method == 'POST':
        title = request.POST.get('title', '')
        description = request.POST.get('description', '')
        number = request.POST.get('number', '')
        right = request.POST.get('right', '')
        film = Film(creator = request.user, holder = request.user, drifting = False, title = title, description = description, number = number, 
                    used_number = 0, developed = False, right = right, drift_direction = "")
        try:
            film.save()
            return HttpResponse(simplejson.dumps({'msg':'OK'}))
        except:
            return HttpResponse(simplejson.dumps({'msg':'对不起，系统好像有些问题'}))
    else:
        return HttpResponse(simplejson.dumps({'msg':'非post'}))
